package eirkdbd.lab1.membership.functions;

import java.util.ArrayList;
import java.util.List;

import eirkdbd.lab1.data.Team;
import eirkdbd.lab1.membership.MembershipFunction;
import eirkdbd.lab1.membership.functions.helpers.norms.Norm;

/**
 * Represents composed membership function
 * @author pajac
 *
 */
public class ComposedMembershipFunction implements MembershipFunction {

	private List<MembershipFunction> mfs;
	private List<Norm> norms;
	
	/**
	 * Constructor of ComposedMembershipFunction
	 * @param mfs - set of membership functions to compose
	 * @param norms - set of norms for composition
	 * mfs set size must be one bigger than norms set size
	 */
	public ComposedMembershipFunction(List<MembershipFunction> mfs, List<Norm> norms){
		System.out.println(mfs + " " + norms);
		if ((mfs.size() - norms.size()) != 1 && mfs.size() != 1)
			throw new IllegalArgumentException("Incorrect membership functions and norms set");
		this.mfs = mfs;
		this.norms = norms;
	}
	
	/**
	 * Constructor of ComposedMembershipFunction
	 * @param mf1 - membership function 1
	 * @param norm - norm 
	 * @param mf2 - membership function 2
	 */
	public ComposedMembershipFunction(MembershipFunction mf1, Norm norm, MembershipFunction mf2){
		List<MembershipFunction> mfs = new ArrayList<MembershipFunction>();
		List<Norm> norms = new ArrayList<Norm>();
		mfs.add(mf1);
		mfs.add(mf2);
		norms.add(norm);
		this.mfs = mfs;
		this.norms = norms;
	}
	
	public double getValue(Team team) {
		double value = norms.get(0).value(mfs.get(0).getValue(team), mfs.get(1).getValue(team));
		for (int i=1; i < norms.size(); ++i){
			value = norms.get(i).value(value, mfs.get(i+1).getValue(team));
		}
		return value;
	}

}
